import 'package:flutter/material.dart';
import 'package:status_bar_control/status_bar_control.dart';

/// 支持自定义样式的沉浸式导航栏
class HiNavigationBar extends StatelessWidget {
  final StatusBarStyle statusStyle;
  final Color color;
  final double height;
  final Widget child;

  const HiNavigationBar({
    super.key,
    this.statusStyle = StatusBarStyle.DARK_CONTENT,
    this.color = Colors.white,
    this.height = 46,
    required this.child,
  });

  @override
  Widget build(BuildContext context) {
    _statusBarInit();
    var top = MediaQuery.of(context).padding.top; // 状态栏高度
    return Container(
      width: MediaQuery.of(context).size.width,
      height: top + height,
      padding: EdgeInsets.only(top: top),
      decoration: BoxDecoration(color: color),
      child: child,
    );
  }

  void _statusBarInit() {
    // 状态栏样式设置
    StatusBarControl.setColor(color, animated: false);
    StatusBarControl.setStyle(statusStyle == StatusBarStyle.DARK_CONTENT
        ? StatusBarStyle.DARK_CONTENT
        : StatusBarStyle.LIGHT_CONTENT);
  }
}
